package study.day6.t1;

import java.util.Scanner;
//Exception所属的是检查异常
class AgeException extends Exception{
    public AgeException(String msg){
        super(msg);
    }
}
//只有一个public修饰的类
public class T1 {
    public static void main(String[] args) {
        //自定义异常
        Scanner input=new Scanner(System.in);
        System.out.println("输入姓名：");
        String name = input.next();
        System.out.println("输入年龄：");
        int age = input.nextInt();
        try{
            if(age<0) {
                //年龄非法
                throw new AgeException("年龄不能是负数");
            }
            System.out.println("姓名"+name);
            System.out.println("年龄"+age);
         }catch (AgeException ex) {
             throw new RuntimeException(ex.getMessage());
         }finally {
             System.out.println("程序结束");
         }
    }
}
